package vip.xiaonuo.modular.xygenealogy.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.annotion.version.ApiVersionSwagger;
import vip.xiaonuo.modular.xygenealogy.entity.XyGenealogy;
import vip.xiaonuo.modular.xygenealogy.form.XyGenealogyForm;
import vip.xiaonuo.modular.xygenealogy.service.XyGenealogyService;
import vip.xiaonuo.modular.xygenealogy.vo.GroupGenealogyVo;
import vip.xiaonuo.modular.xygenealogycate.entity.XyGenealogyCate;
import vip.xiaonuo.modular.xygenealogycate.service.XyGenealogyCateService;
import vip.xiaonuo.sys.core.msg.Result;

import java.util.List;

import static vip.xiaonuo.sys.core.msg.ResultUtils.success;

@RestController
@Api(tags = "谱文apis")
@ApiVersionSwagger
@RequestMapping("/genealogy")
public class ApiGenealogyController {

    @Autowired
    private XyGenealogyCateService genealogyCateService;

    @Autowired
    private XyGenealogyService genealogyService;

    @GetMapping("/findGenealogyCateAll")
    @ApiOperation("查看谱文分类全部列表")
    public Result<List<XyGenealogyCate>> findGenealogyCateAll(){
        return success(genealogyCateService.list());
    }

    @PostMapping("/genealogySave")
    @ApiOperation("添加谱文")
    public Result genealogySave(@RequestBody @Validated XyGenealogyForm xyGenealogyForm){
        genealogyService.genealogySave(xyGenealogyForm);
        return success();
    }

    @GetMapping("/groupGenealogyList/{logyId}")
    @ApiOperation(value = "根据谱文的分类分组查询谱文列表信息",notes = "传入家谱编号")
    public Result<List<GroupGenealogyVo>> groupGenealogyList(@PathVariable String logyId){
        return success(genealogyService.groupGenealogyList(logyId));
    }

    @GetMapping("/cateGenealogyList/{cateId}/{logyId}")
    @ApiOperation("根据谱文分类id查询谱文列表")
    public Result<List<XyGenealogy>> cateGenealogyList(@PathVariable String cateId,@PathVariable String logyId){
        return success(genealogyService.list(Wrappers.<XyGenealogy>lambdaQuery().eq(XyGenealogy::getCateId,cateId).eq(XyGenealogy::getLogyId,logyId)));
    }

    @GetMapping("/genealogyInfo/{id}")
    @ApiOperation("根据谱文的id 查询谱文的详情")
    public Result<XyGenealogy> genealogyInfo(@PathVariable String id){
        return success(genealogyService.getById(id));
    }







}
